package com.yand.thread.rabbitRun2;

public class Rabbit extends Thread {

    private int speed = 20;

    private int sum = 0;

    private int length = 100;
    private Callback callback;


    public void setCallback(Callback callback) {
        this.callback = callback;
    }

    public void run(){
        while((length-sum) > 0){
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            sum += speed;
            System.out.println("本兔子跑了"+sum+"米");
            System.out.println("距离终点还剩下"+(length-sum)+"米");
            if(sum % 30 == 0){
                System.out.println("本兔子要休息5秒");
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

            }
        }
        System.out.println("本兔子赢了，小乌龟给我stop");
        //跑完了兔子赢了， 通知乌龟不用跑了
        callback.stopTortoise();














    }
}
